package com.bootcamp.javase2.io;

import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Scanner;

/**
 * @program: IOCode
 * @description: create file from Scanner but end with a String
 * @author: Keyu Li
 * @create: 2021-09-09 20:12
 **/

public class createFileEnd {
    static final String END_MARK = "end";
    static final Scanner SCANNER = new Scanner(System.in);

    public static void main(String[] args) throws IOException {
        // input name
        System.out.println("please input File name with txt file type: ");
        String fileName = SCANNER.nextLine();
        FileOutputStream out = new FileOutputStream(fileName);

        //input content
        System.out.println("please input file content(\"end\"): ");
        while (true) {
            String temp = SCANNER.nextLine();
            if (temp.endsWith(END_MARK))    break;
            byte[] bytes = temp.getBytes();
            out.write(bytes);
        }

        //close
        out.close();
        // print
        PrintFile.print(fileName);
    }
}
